"""额度申请审核页面"""
from selenium.webdriver.common.by import By

from base.page_base import BasePage


class QuotaAptReview(BasePage):
    """额度申请审核"""

    #部分变量
    username = "13612342289"

    # 元素定位
    __loan_management_btn = By.LINK_TEXT, '借款管理' # 借款管理按钮
    __quota_management_btn = By.XPATH, '//span[text()="额度管理"]' # 额度管理按钮
    __quota_application_review_btn = By.XPATH, '//a[contains(normalize-space(.), "额度申请审核")]' # 额度申请审核按钮
    __cd_iframe_list_page = By.ID, 'iframe_box' # 切换为列表页面iframe
    __username_search = By.XPATH, '//input[@ng-model="SpageData[formBox.name]"]' # 用户名搜索框
    __search_btn = By.XPATH, '//input[@value="搜索"]' # 搜索按钮
    __application_record = By.XPATH, f'//span[text()={username}]' # 指定的申请记录
    __review_btn = By.XPATH, '//span[text()="审核"]' # 审核按钮
    __cd_iframe_review_page = By.ID, 'xubox_iframe1' # 切换为审核页面iframe
    __application_pass_btn = By.XPATH, '//span[text()="通过"]' # 通过按钮
    __review_note = By.XPATH,'//textarea[@ng-model="EformData[items.name]"]' # 审核备注
    __review_verifycode = By.XPATH, '//input[@ng-model="EformData[ispanlist.name]"]' # 验证码
    __save_btn = By.XPATH, '//input[@value="保存"]' # 保存按钮
    __assert_success_text = By.XPATH, '//span[text()="审核成功"]' # 审核成功提示断言

    def loan_management_click(self):
        """点击借款管理按钮"""
        self.base_click(self.__loan_management_btn)

    def quota_management_click(self):
        """点击额度管理按钮"""
        self.base_click(self.__quota_management_btn)

    def quota_application_review_click(self):
        """点击额度申请审核按钮"""
        self.base_click(self.__quota_application_review_btn)

    def switch_to_iframe_list_page(self):
        """切换到列表页面"""
        self.base_switch_frame(self.__cd_iframe_list_page)

    def input_username_search(self):
        """输入用户名"""
        self.base_input(self.__username_search, f'{self.username}')

    def search_click(self):
        """点击搜索按钮"""
        self.base_click(self.__search_btn)

    def application_record_click(self):
        """点击指定的申请记录"""
        self.base_click_retry(self.__application_record)

    def review_click(self):
        """点击审核按钮"""
        self.base_click(self.__review_btn)

    def switch_to_iframe_review_page(self):
        """切换到审核页面"""
        self.base_switch_frame(self.__cd_iframe_review_page)

    def application_pass_click(self):
        """点击通过按钮"""
        self.base_click(self.__application_pass_btn)

    def review_note_input(self):
        """输入审核备注"""
        self.base_input(self.__review_note, '测试007')

    def review_verifycode_input(self):
        """输入验证码"""
        self.base_input(self.__review_verifycode, '8888')

    def save_click(self):
        """点击保存按钮"""
        self.base_click(self.__save_btn)

    def assert_review_success(self):
        """断言额度申请审核成功"""
        return self.base_get_text(self.__assert_success_text)

    def quota_application_review_process(self):
        """额度申请审核流程"""
        self.loan_management_click() # 点击借款管理按钮
        self.quota_management_click() # 点击额度管理按钮
        self.quota_application_review_click() # 点击额度申请审核按钮
        self.switch_to_iframe_list_page() # 切换到列表页面
        self.input_username_search() # 输入用户名
        self.search_click() # 点击搜索按钮
        self.application_record_click() # 点击指定的申请记录
        self.review_click() # 点击审核按钮
        self.switch_to_iframe_review_page() # 切换到审核页面
        self.application_pass_click() # 点击通过按钮
        self.review_note_input() # 输入审核备注
        self.review_verifycode_input() # 输入验证码
        self.save_click() # 点击保存按钮


